package com.gaoxin.api.contronller.statisController;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.gaoxin.api.entity.statisentity.Classroom;
import com.gaoxin.api.entity.statisentity.StudentInfo;
import com.gaoxin.api.service.statisservice.StatisClassStuService;
import com.google.common.collect.Maps;

import io.swagger.annotations.Api;

/**
 * 统计班级学生信息
 * @author zhaozhenshe
 *2018-07-14
 */
@RestController
@RequestMapping("/app/student/")
@Api(tags="统计班级学生接口")
public class StatisStudentController {
	@Autowired
	private StatisClassStuService statisClassStuService;
	
	@RequestMapping(value="/queryClassStu",method=RequestMethod.POST,produces = "application/json;charset=UTF-8")
	public String queryClassStu(@RequestBody Map<String,String> paramMap){
		String jsonData = null;
		try {
			String classId = paramMap.get("classId");
			Classroom classroom2 = statisClassStuService.queryClassroom(classId);
			if(classroom2==null){
				Map<String, Object> map = Maps.newLinkedHashMap();
				map.put("code","100503");
				map.put("errmsg","该班级不存在，请核对后重新输入！");
				jsonData = JSON.toJSONString(map);
				return jsonData;
			}
			Map<String, Object> map = Maps.newLinkedHashMap();
			List<StudentInfo> arrayList = statisClassStuService.queryStudentListByClassId(classId);
			if(arrayList.size()!=0&&arrayList!=null){
				Classroom classroom = new Classroom();
				classroom.setArrayList(arrayList);
				map.put("code","0");
				map.put("results",classroom);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code","100504");
				map.put("errmsg","无该班级学生信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
}
